﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.Admin
{
    public partial class ListOfferJobs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["AdminLogin2"] != null)
                {
                    int atid = Convert.ToInt32(Session["AdminLogin2"]);

                    Bind(atid);
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='adminlogin2.aspx'");
                }
            }
            //if (!IsPostBack)
            //{
            //    Bind(2);
            //}
            
        }
        //处理中
        protected void lbn_update_Click(object sender, EventArgs e)
        {
            string idList = this.GetSelIDlist();

            if (!string.IsNullOrEmpty(idList))
            {
                if (new lcmyjobs.BLL.enterprise_offer().UpdateWhere("status", "1", idList))
                {
                    //Maticsoft.Common.MessageBox.Show(this, "处理中！");
                    if (Session["AdminLogin2"] != null)
                    {
                        int atid = Convert.ToInt32(Session["AdminLogin2"]);

                        Bind(atid);
                    }
                }

            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "处理失败！");
            }
        }
        //失败
        protected void lbn_cancle_Click(object sender, EventArgs e)
        {
            string idList = this.GetSelIDlist();

            if (!string.IsNullOrEmpty(idList))
            {
                if (new lcmyjobs.BLL.enterprise_offer().UpdateWhere("status", "3", idList))
                {
                    //Maticsoft.Common.MessageBox.Show(this, "状态已改变为失败！");
                    if (Session["AdminLogin2"] != null)
                    {
                        int atid = Convert.ToInt32(Session["AdminLogin2"]);

                        Bind(atid);
                    }
                }

            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "状态没有改变出现错误！");
            }
        }
        //成功
        protected void lbn_issuccess_Click(object sender, EventArgs e)
        {
            string idList = this.GetSelIDlist();

            if (!string.IsNullOrEmpty(idList))
            {
                if (new lcmyjobs.BLL.enterprise_offer().UpdateWhere("status", "2", idList))
                {
                    //Maticsoft.Common.MessageBox.Show(this, "状态已改变为成功！");
                    if (Session["AdminLogin2"] != null)
                    {
                        int atid = Convert.ToInt32(Session["AdminLogin2"]);

                        Bind(atid);
                    }
                }

            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "状态没有改变出现错误！");
            }
        }
        //删除
        protected void lbn_delete_Click(object sender, EventArgs e)
        {
            string idList = this.GetSelIDlist();

            if (!string.IsNullOrEmpty(idList))
            {
                if (new lcmyjobs.BLL.enterprise_offer().DeleteList(idList))
                {
                    //Maticsoft.Common.MessageBox.Show(this, "删除成功！");
                    if (Session["AdminLogin2"] != null)
                    {
                        int atid = Convert.ToInt32(Session["AdminLogin2"]);

                        Bind(atid);
                    }
                }

            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "删除失败！");
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_check")//查看
            {
                if (e.CommandArgument != null)
                {
                    Session["ShowEnterpriseOffer"] = e.CommandArgument;

                    Maticsoft.Common.MessageBox.ResponseScript(this, "OpenPopDialog('ShowEnterpriseOffer.aspx','800px','500px')");
                }
            }
            if (e.CommandName == "lbn_del")
            {
                if (e.CommandArgument != null)
                {

                    if (new lcmyjobs.BLL.enterprise_offer().Delete(Convert.ToInt32(e.CommandArgument)))
                    {
                        //Maticsoft.Common.MessageBox.Show(this, "删除成功！");
                        if (Session["AdminLogin2"] != null)
                        {
                            int atid = Convert.ToInt32(Session["AdminLogin2"]);

                            Bind(atid);
                        }
                    }

                }
            }

        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            if (Session["AdminLogin2"] != null)
            {
                int atid = Convert.ToInt32(Session["AdminLogin2"]);

                Bind(atid);
            }
        }

        private void Bind(int atid)
        {
            int count = 0;

            DataSet ds = new lcmyjobs.BLL.enterprise_releasejob().GetAllOfferJobdByAtid(atid, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out count);

            this.lbl_count.Text = count.ToString();

            this.AspNetPager1.RecordCount = count;

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }

        /// <summary>
        /// 获取主键ID列表
        /// </summary>
        /// <returns></returns>
        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)this.GridView1.Rows[i].FindControl("cbo_rid");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (GridView1.DataKeys[i].Value != null)
                    {
                        idlist += GridView1.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }
        public string GetBH(string str)
        {
            return  str.ToString().PadLeft(6, '0');
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.Cells[8].Text == "×")
            {
                e.Row.Cells[8].ControlStyle.ForeColor = System.Drawing.Color.Red;
            }
        }

        

       
    }
}